--region [dbo].[usp_InsertDANGKY]
------------------------------------------------------------------------------------------------------------------------
CREATE PROCEDURE [dbo].[usp_InsertDANGKY]
	@TieuDe nvarchar(100),
	@MaSinhVien int,
	@MaKhuVucThue int,
	@MaLoaiNha int,
	@GiaThue int,
	@DienTich float,
	@SucChua int,
	@ThoiGianDangKy varchar(10),
	@ThoiGianDong varchar(10),
	@OGhep int,
	@OChungChu int,
	@GanCho int,
	@GanTramXeBuyt int,
	@ChoNuThue int,
	@ChoNamThue int,
	@ChoNauAn int,
	@Internet int,
	@TruyenHinhCap int,
	@TrangThai int,
	@MaDangKy int OUTPUT
AS

SET NOCOUNT ON

INSERT INTO [dbo].[DANGKY] (
	[TieuDe],
	[MaSinhVien],
	[MaKhuVucThue],
	[MaLoaiNha],
	[GiaThue],
	[DienTich],
	[SucChua],
	[ThoiGianDangKy],
	[ThoiGianDong],
	[OGhep],
	[OChungChu],
	[GanCho],
	[GanTramXeBuyt],
	[ChoNuThue],
	[ChoNamThue],
	[ChoNauAn],
	[Internet],
	[TruyenHinhCap],
	[TrangThai]
) VALUES (
	@TieuDe,
	@MaSinhVien,
	@MaKhuVucThue,
	@MaLoaiNha,
	@GiaThue,
	@DienTich,
	@SucChua,
	@ThoiGianDangKy,
	@ThoiGianDong,
	@OGhep,
	@OChungChu,
	@GanCho,
	@GanTramXeBuyt,
	@ChoNuThue,
	@ChoNamThue,
	@ChoNauAn,
	@Internet,
	@TruyenHinhCap,
	@TrangThai
)

SET @MaDangKy = SCOPE_IDENTITY()

--endregion

GO

--region [dbo].[usp_UpdateDANGKY]
------------------------------------------------------------------------------------------------------------------------
CREATE PROCEDURE [dbo].[usp_UpdateDANGKY]
	@MaDangKy int,
	@TieuDe nvarchar(100),
	@MaSinhVien int,
	@MaKhuVucThue int,
	@MaLoaiNha int,
	@GiaThue int,
	@DienTich float,
	@SucChua int,
--	@ThoiGianDangKy varchar(10),
--	@ThoiGianDong varchar(10),
	@OGhep int,
	@OChungChu int,
	@GanCho int,
	@GanTramXeBuyt int,
	@ChoNuThue int,
	@ChoNamThue int,
	@ChoNauAn int,
	@Internet int,
	@TruyenHinhCap int,
	@TrangThai int
AS

SET NOCOUNT ON

UPDATE [dbo].[DANGKY] SET
	[TieuDe] = @TieuDe,
	[MaSinhVien] = @MaSinhVien,
	[MaKhuVucThue] = @MaKhuVucThue,
	[MaLoaiNha] = @MaLoaiNha,
	[GiaThue] = @GiaThue,
	[DienTich] = @DienTich,
	[SucChua] = @SucChua,
--	[ThoiGianDangKy] = @ThoiGianDangKy,
--	[ThoiGianDong] = @ThoiGianDong,
	[OGhep] = @OGhep,
	[OChungChu] = @OChungChu,
	[GanCho] = @GanCho,
	[GanTramXeBuyt] = @GanTramXeBuyt,
	[ChoNuThue] = @ChoNuThue,
	[ChoNamThue] = @ChoNamThue,
	[ChoNauAn] = @ChoNauAn,
	[Internet] = @Internet,
	[TruyenHinhCap] = @TruyenHinhCap,
	[TrangThai] = @TrangThai
WHERE
	[MaDangKy] = @MaDangKy

--endregion

GO

--region [dbo].[usp_DeleteDANGKY]
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_DeleteDANGKY]
	@MaDangKy int
AS

SET NOCOUNT ON

DELETE FROM [dbo].[DANGKY]
WHERE
	[MaDangKy] = @MaDangKy

--endregion

GO

------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------
-- kiem tra ton tai tai khoan
create proc usp_KTTonTaiEmailChuNha
	@Email varchar(50),
	@flag int out
as
begin
	if (exists(select *from CHUNHA where Email=@Email)) begin
		print 'da ton tai'
		set @flag=1
	end
if (not exists(select *from CHUNHA where Email=@Email)) begin
		print 'chua ton tai'
		set @flag=0
	end
end

GO

--region [dbo].[usp_InsertCHUNHA]
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_InsertCHUNHA]
	@MaTaiKhoan int,
	@HoTen nvarchar(50),
	@DienThoai varchar(11),
	@CMND varchar(9),
	@Email varchar(50),
	@MaChuNha int OUTPUT
AS

SET NOCOUNT ON

INSERT INTO [dbo].[CHUNHA] (
	[MaTaiKhoan],
	[HoTen],
	[DienThoai],
	[CMND],
	[Email]
) VALUES (
	@MaTaiKhoan,
	@HoTen,
	@DienThoai,
	@CMND,
	@Email
)

SET @MaChuNha = SCOPE_IDENTITY()

--endregion

GO

--region [dbo].[usp_UpdateCHUNHA]
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_UpdateCHUNHA]
	@MaChuNha int,
	@HoTen nvarchar(50),
	@DienThoai varchar(11),
	@CMND varchar(9),
	@Email varchar(50)
AS

SET NOCOUNT ON

UPDATE [dbo].[CHUNHA] SET
	[HoTen] = @HoTen,
	[DienThoai] = @DienThoai,
	[CMND] = @CMND,
	[Email] = @Email
WHERE
	[MaChuNha] = @MaChuNha

--endregion

GO

--region [dbo].[usp_DeleteCHUNHA]
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_DeleteCHUNHA]
	@MaChuNha int
AS

SET NOCOUNT ON

DELETE FROM [dbo].[CHUNHA]
WHERE
	[MaChuNha] = @MaChuNha

--endregion
------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------
--region [dbo].[usp_InsertDANGTIN]
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_InsertDANGTIN]
	@TieuDeTin nvarchar(100),
	@MaLoaiTin int,
	@MaLoaiNha int,
	@MaChuNha int,
	@MaDiaChi int,
	@GiaThue int,
	@DienTich float,
	@SucChua int,
	@TinhTrang int,
	@ThoiGianDangTin varchar(10),
	@ThoiGianDongTin varchar(10),
	@OGhep int,
	@OChungChu int,
	@GanCho int,
	@GanTramXeBuyt int,
	@ChoNuThue int,
	@ChoNamThue int,
	@ChoNauAn int,
	@Internet int,
	@TruyenHinhCap int,
	@MaDangTin int OUTPUT
AS

SET NOCOUNT ON

INSERT INTO [dbo].[DANGTIN] (
	[TieuDeTin],
	[MaLoaiTin],
	[MaLoaiNha],
	[MaChuNha],
	[MaDiaChi],
	[GiaThue],
	[DienTich],
	[SucChua],
	[TinhTrang],
	[ThoiGianDangTin],
	[ThoiGianDongTin],
	[OGhep],
	[OChungChu],
	[GanCho],
	[GanTramXeBuyt],
	[ChoNuThue],
	[ChoNamThue],
	[ChoNauAn],
	[Internet],
	[TruyenHinhCap]
) VALUES (
	@TieuDeTin,
	@MaLoaiTin,
	@MaLoaiNha,
	@MaChuNha,
	@MaDiaChi,
	@GiaThue,
	@DienTich,
	@SucChua,
	@TinhTrang,
	@ThoiGianDangTin,
	@ThoiGianDongTin,
	@OGhep,
	@OChungChu,
	@GanCho,
	@GanTramXeBuyt,
	@ChoNuThue,
	@ChoNamThue,
	@ChoNauAn,
	@Internet,
	@TruyenHinhCap
)

SET @MaDangTin = SCOPE_IDENTITY()

--endregion

GO

--region [dbo].[usp_UpdateDANGTIN]
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_UpdateDANGTIN]
	@MaDangTin int,
	@TieuDeTin nvarchar(100),
	@MaLoaiTin int,
	@MaLoaiNha int,
	@MaChuNha int,
	@MaDiaChi int,
	@GiaThue int,
	@DienTich float,
	@SucChua int,
	@TinhTrang int,
--	@ThoiGianDangTin varchar(10),
--	@ThoiGianDongTin varchar(10),
	@OGhep int,
	@OChungChu int,
	@GanCho int,
	@GanTramXeBuyt int,
	@ChoNuThue int,
	@ChoNamThue int,
	@ChoNauAn int,
	@Internet int,
	@TruyenHinhCap int
AS

SET NOCOUNT ON

UPDATE [dbo].[DANGTIN] SET
	[TieuDeTin] = @TieuDeTin,
	[MaLoaiTin] = @MaLoaiTin,
	[MaLoaiNha] = @MaLoaiNha,
	[MaChuNha] = @MaChuNha,
	[MaDiaChi] = @MaDiaChi,
	[GiaThue] = @GiaThue,
	[DienTich] = @DienTich,
	[SucChua] = @SucChua,
	[TinhTrang] = @TinhTrang,
--	[ThoiGianDangTin] = @ThoiGianDangTin,
--	[ThoiGianDongTin] = @ThoiGianDongTin,
	[OGhep] = @OGhep,
	[OChungChu] = @OChungChu,
	[GanCho] = @GanCho,
	[GanTramXeBuyt] = @GanTramXeBuyt,
	[ChoNuThue] = @ChoNuThue,
	[ChoNamThue] = @ChoNamThue,
	[ChoNauAn] = @ChoNauAn,
	[Internet] = @Internet,
	[TruyenHinhCap] = @TruyenHinhCap
WHERE
	[MaDangTin] = @MaDangTin

--endregion

GO

--region [dbo].[usp_DeleteDANGTIN]
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_DeleteDANGTIN]
	@MaDangTin int
AS

SET NOCOUNT ON

DELETE FROM [dbo].[DANGTIN]
WHERE
	[MaDangTin] = @MaDangTin

--endregion

GO


------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------
-- kiem tra ton tai tai khoan
create proc usp_KTTonTaiTAIKHOAN
	@TenTaiKhoan varchar(30),
	@flag int out
as
begin
	if (exists(select *from TAIKHOAN where TenTaiKhoan=@TenTaiKhoan)) begin
		print 'da ton tai'
		set @flag=1
	end
if (not exists(select *from TAIKHOAN where TenTaiKhoan=@TenTaiKhoan)) begin
		print 'chua ton tai'
		set @flag=0
	end
end
go
--drop proc usp_KTTonTaiTAIKHOAN
--exec usp_KTTonTaiTAIKHOAN 'hoangphung',0
--- kiem tra dang nhap--------------------------------
create proc usp_KTDangNhap
	@TenTaiKhoan varchar(30),
	@MatKhau varchar(50),
	@Flag int output
as
	if (exists(select *from TAIKHOAN where TenTaiKhoan=@TenTaiKhoan and MatKhau=@MatKhau and MaLoai=1)) begin
		set @Flag=1
	end
	else
		if (exists(select *from TAIKHOAN where TenTaiKhoan=@TenTaiKhoan and MatKhau=@MatKhau and MaLoai=2)) begin
			set @Flag=2
		end
		else
			if (exists(select *from TAIKHOAN where TenTaiKhoan=@TenTaiKhoan and MatKhau=@MatKhau and MaLoai=3)) begin
				set @Flag=3
			end
			else
				set @Flag=0
------------------
---------------------------------
GO
--region [dbo].[usp_InsertTAIKHOAN]
CREATE PROCEDURE [dbo].[usp_InsertTAIKHOAN]
	@TenTaiKhoan varchar(30),
	@MatKhau varchar(50),
	@MaLoai int,
	@TrangThai int,
	@MaTaiKhoan int OUTPUT
AS
SET NOCOUNT ON
INSERT INTO [dbo].[TAIKHOAN] (
	[TenTaiKhoan],
	[MatKhau],
	[MaLoai],
	[TrangThai]
) VALUES (
	@TenTaiKhoan,
	@MatKhau,
	@MaLoai,
	@TrangThai
)
SET @MaTaiKhoan = SCOPE_IDENTITY()
--endregion
GO
CREATE PROCEDURE [dbo].[usp_UpdateTAIKHOAN]
	@MaTaiKhoan int,
	@TenTaiKhoan varchar(30),
	@MatKhau varchar(50),
	@MaLoai int,
	@TrangThai int
AS
SET NOCOUNT ON
UPDATE [dbo].[TAIKHOAN] SET
	[TenTaiKhoan] = @TenTaiKhoan,
	[MatKhau] = @MatKhau,
	[MaLoai] = @MaLoai,
	[TrangThai] = @TrangThai
WHERE
	[MaTaiKhoan] = @MaTaiKhoan
--endregion
GO
--region [dbo].[usp_DeleteTAIKHOAN]
CREATE PROCEDURE [dbo].[usp_DeleteTAIKHOAN]
	@MaTaiKhoan int
AS
SET NOCOUNT ON
DELETE FROM [dbo].[TAIKHOAN]
WHERE
	[MaTaiKhoan] = @MaTaiKhoan

--endregion
CREATE PROCEDURE [dbo].[usp_UpdateTrangThaiTAIKHOAN]
	@MaTaiKhoan int,
	@TrangThai int
AS
SET NOCOUNT ON
UPDATE [dbo].[TAIKHOAN] SET
	[TrangThai] = @TrangThai
WHERE
	[MaTaiKhoan] = @MaTaiKhoan
--endregion
GO
------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------
-- kiem tra ton tai tai khoan
create proc usp_KTTonTaiEmailSV
	@Email varchar(50),
	@flag int out
as
begin
	if (exists(select *from SINHVIEN where Email=@Email)) begin
		set @flag=1
	end
if (not exists(select *from SINHVIEN where Email=@Email)) begin
		set @flag=0
	end
end
--region Drop Existing Procedures

GO

--region [dbo].[usp_InsertSINHVIEN]

CREATE PROCEDURE [dbo].[usp_InsertSINHVIEN]
	@MaTaiKhoan int,
	@HoTen nvarchar(50),
	@DienThoai varchar(11),
	@Email varchar(50),
	@CMND varchar(9),
	@Truong nvarchar(50),
	@MaSinhVien int OUTPUT
AS

SET NOCOUNT ON

INSERT INTO [dbo].[SINHVIEN] (
	[MaTaiKhoan],
	[HoTen],
	[DienThoai],
	[Email],
	[CMND],
	[Truong]
) VALUES (
	@MaTaiKhoan,
	@HoTen,
	@DienThoai,
	@Email,
	@CMND,
	@Truong
)

SET @MaSinhVien = SCOPE_IDENTITY()

--endregion

GO

--region [dbo].[usp_UpdateSINHVIEN]


CREATE PROCEDURE [dbo].[usp_UpdateSINHVIEN]
	@MaSinhVien int,
	@HoTen nvarchar(50),
	@DienThoai varchar(11),
	@Email varchar(50),
	@CMND varchar(9),
	@Truong nvarchar(50)
AS

SET NOCOUNT ON

UPDATE [dbo].[SINHVIEN] SET
	[HoTen] = @HoTen,
	[DienThoai] = @DienThoai,
	[Email] = @Email,
	[CMND] = @CMND,
	[Truong] = @Truong
WHERE
	[MaSinhVien] = @MaSinhVien

--endregion

GO

--region [dbo].[usp_DeleteSINHVIEN]

CREATE PROCEDURE [dbo].[usp_DeleteSINHVIEN]
	@MaSinhVien int
AS

SET NOCOUNT ON

DELETE FROM [dbo].[SINHVIEN]
WHERE
	[MaSinhVien] = @MaSinhVien

--endregion

------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------
--region [dbo].[usp_InsertQUANTRI]
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_InsertQUANTRI]
	@MaTaiKhoan int,
	@HoTen nvarchar(50),
	@DienThoai varchar(11),
	@CMND varchar(9),
	@Email varchar(50),
	@MaQuanTri int OUTPUT
AS

SET NOCOUNT ON

INSERT INTO [dbo].[QUANTRI] (
	[MaTaiKhoan],
	[HoTen],
	[DienThoai],
	[CMND],
	[Email]
) VALUES (
	@MaTaiKhoan,
	@HoTen,
	@DienThoai,
	@CMND,
	@Email
)

SET @MaQuanTri = SCOPE_IDENTITY()

--endregion

GO

--region [dbo].[usp_UpdateQUANTRI]
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_UpdateQUANTRI]
	@MaQuanTri int,
	@MaTaiKhoan int,
	@HoTen nvarchar(50),
	@DienThoai varchar(11),
	@CMND varchar(9),
	@Email varchar(50)
AS

SET NOCOUNT ON

UPDATE [dbo].[QUANTRI] SET
	[MaTaiKhoan] = @MaTaiKhoan,
	[HoTen] = @HoTen,
	[DienThoai] = @DienThoai,
	[CMND] = @CMND,
	[Email] = @Email
WHERE
	[MaQuanTri] = @MaQuanTri

--endregion

GO

--region [dbo].[usp_DeleteQUANTRI]
------------------------------------------------------------------------------------------------------------------------
CREATE PROCEDURE [dbo].[usp_DeleteQUANTRI]
	@MaQuanTri int
AS

SET NOCOUNT ON

DELETE FROM [dbo].[QUANTRI]
WHERE
	[MaQuanTri] = @MaQuanTri

--endregion

------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------
--region [dbo].[usp_InsertPHIEUGIOITHIEU]
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_InsertPHIEUGIOITHIEU]
	@MaDangTin int,
	@MaSinhVien int,
	@GiaTien int,
	@NgayLapPhieu varchar(10),
	@MaPhieu int OUTPUT
AS

SET NOCOUNT ON

INSERT INTO [dbo].[PHIEUGIOITHIEU] (
	[MaDangTin],
	[MaSinhVien],
	[GiaTien],
	[NgayLapPhieu]
) VALUES (
	@MaDangTin,
	@MaSinhVien,
	@GiaTien,
	@NgayLapPhieu
)

SET @MaPhieu = SCOPE_IDENTITY()

--endregion

GO

--region [dbo].[usp_UpdatePHIEUGIOITHIEU]
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_UpdatePHIEUGIOITHIEU]
	@MaPhieu int,
	@MaDangTin int,
	@MaSinhVien int,
	@GiaTien int,
	@NgayLapPhieu varchar(10)
AS

SET NOCOUNT ON

UPDATE [dbo].[PHIEUGIOITHIEU] SET
	[MaDangTin] = @MaDangTin,
	[MaSinhVien] = @MaSinhVien,
	[GiaTien] = @GiaTien,
	[NgayLapPhieu] = @NgayLapPhieu
WHERE
	[MaPhieu] = @MaPhieu

--endregion

GO

--region [dbo].[usp_DeletePHIEUGIOITHIEU]
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_DeletePHIEUGIOITHIEU]
	@MaPhieu int
AS

SET NOCOUNT ON

DELETE FROM [dbo].[PHIEUGIOITHIEU]
WHERE
	[MaPhieu] = @MaPhieu

--endregion

GO


------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------
--region [dbo].[usp_InsertLOAITIN]

CREATE PROCEDURE [dbo].[usp_InsertLOAITIN]
	@TenLoai nvarchar(50),
	@DonGia int,
	@MaLoaiTin int OUTPUT
AS

SET NOCOUNT ON

INSERT INTO [dbo].[LOAITIN] (
	[TenLoai],
	[DonGia]
) VALUES (
	@TenLoai,
	@DonGia
)

SET @MaLoaiTin = SCOPE_IDENTITY()

--endregion

GO

--region [dbo].[usp_UpdateLOAITIN]
CREATE PROCEDURE [dbo].[usp_UpdateLOAITIN]
	@MaLoaiTin int,
	@TenLoai nvarchar(50),
	@DonGia int
AS

SET NOCOUNT ON

UPDATE [dbo].[LOAITIN] SET
	[TenLoai] = @TenLoai,
	[DonGia] = @DonGia
WHERE
	[MaLoaiTin] = @MaLoaiTin

--endregion

GO

--region [dbo].[usp_DeleteLOAITIN]
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_DeleteLOAITIN]
	@MaLoaiTin int
AS

SET NOCOUNT ON

DELETE FROM [dbo].[LOAITIN]
WHERE
	[MaLoaiTin] = @MaLoaiTin

--endregion
------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------
--region [dbo].[usp_InsertLOAINHA]

CREATE PROCEDURE [dbo].[usp_InsertLOAINHA]
	@TenLoaiNha nvarchar(50),
	@MaLoaiNha int OUTPUT
AS

SET NOCOUNT ON

INSERT INTO [dbo].[LOAINHA] (
	[TenLoaiNha]
) VALUES (
	@TenLoaiNha
)

SET @MaLoaiNha = SCOPE_IDENTITY()

--endregion

GO

--region [dbo].[usp_UpdateLOAINHA]

CREATE PROCEDURE [dbo].[usp_UpdateLOAINHA]
	@MaLoaiNha int,
	@TenLoaiNha nvarchar(50)
AS

SET NOCOUNT ON

UPDATE [dbo].[LOAINHA] SET
	[TenLoaiNha] = @TenLoaiNha
WHERE
	[MaLoaiNha] = @MaLoaiNha

--endregion

GO

--region [dbo].[usp_DeleteLOAINHA]

CREATE PROCEDURE [dbo].[usp_DeleteLOAINHA]
	@MaLoaiNha int
AS

SET NOCOUNT ON

DELETE FROM [dbo].[LOAINHA]
WHERE
	[MaLoaiNha] = @MaLoaiNha

--endregion
------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------
--region [dbo].[usp_InsertLOAITAIKHOAN]
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_InsertLOAITAIKHOAN]
	@TenLoai nvarchar(20),
	@MaLoai int OUTPUT
AS

SET NOCOUNT ON

INSERT INTO [dbo].[LOAITAIKHOAN] (
	[TenLoai]
) VALUES (
	@TenLoai
)

SET @MaLoai = SCOPE_IDENTITY()

--endregion

GO

--region [dbo].[usp_UpdateLOAITAIKHOAN]
------------------------------------------------------------------------------------------------------------------------
CREATE PROCEDURE [dbo].[usp_UpdateLOAITAIKHOAN]
	@MaLoai int,
	@TenLoai nvarchar(20)
AS

SET NOCOUNT ON

UPDATE [dbo].[LOAITAIKHOAN] SET
	[TenLoai] = @TenLoai
WHERE
	[MaLoai] = @MaLoai

--endregion

GO

--region [dbo].[usp_DeleteLOAITAIKHOAN]

------------------------------------------------------------------------------------------------------------------------
CREATE PROCEDURE [dbo].[usp_DeleteLOAITAIKHOAN]
	@MaLoai int
AS

SET NOCOUNT ON

DELETE FROM [dbo].[LOAITAIKHOAN]
WHERE
	[MaLoai] = @MaLoai

--endregion

GO


------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------
--region [dbo].[usp_InsertKHUVUC]
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_InsertKHUVUC]
	@TenKhuVuc nvarchar(50),
	@MaKhuVuc int OUTPUT
AS

SET NOCOUNT ON

INSERT INTO [dbo].[KHUVUC] (
	[TenKhuVuc]
) VALUES (
	@TenKhuVuc
)

SET @MaKhuVuc = SCOPE_IDENTITY()

--endregion

GO

--region [dbo].[usp_UpdateKHUVUC]
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_UpdateKHUVUC]
	@MaKhuVuc int,
	@TenKhuVuc nvarchar(50)
AS

SET NOCOUNT ON

UPDATE [dbo].[KHUVUC] SET
	[TenKhuVuc] = @TenKhuVuc
WHERE
	[MaKhuVuc] = @MaKhuVuc

--endregion

GO

--region [dbo].[usp_DeleteKHUVUC]
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_DeleteKHUVUC]
	@MaKhuVuc int
AS

SET NOCOUNT ON

DELETE FROM [dbo].[KHUVUC]
WHERE
	[MaKhuVuc] = @MaKhuVuc

--endregion

GO


------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------
--region [dbo].[usp_InsertDIACHI]
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_InsertDIACHI]
	@SoNha varchar(10),
	@Duong nvarchar(50),
	@Phuong nvarchar(50),
	@Quan nvarchar(30),
	@MaDiaChi int OUTPUT
AS

SET NOCOUNT ON

INSERT INTO [dbo].[DIACHI] (
	[SoNha],
	[Duong],
	[Phuong],
	[Quan]
) VALUES (
	@SoNha,
	@Duong,
	@Phuong,
	@Quan
)

SET @MaDiaChi = SCOPE_IDENTITY()

--endregion

GO

--region [dbo].[usp_UpdateDIACHI]
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_UpdateDIACHI]
	@MaDiaChi int,
	@SoNha varchar(10),
	@Duong nvarchar(50),
	@Phuong nvarchar(50),
	@Quan nvarchar(30)
AS

SET NOCOUNT ON

UPDATE [dbo].[DIACHI] SET
	[SoNha] = @SoNha,
	[Duong] = @Duong,
	[Phuong] = @Phuong,
	[Quan] = @Quan
WHERE
	[MaDiaChi] = @MaDiaChi

--endregion

GO

--region [dbo].[usp_DeleteDIACHI]
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_DeleteDIACHI]
	@MaDiaChi int
AS

SET NOCOUNT ON

DELETE FROM [dbo].[DIACHI]
WHERE
	[MaDiaChi] = @MaDiaChi

--endregion

GO

